package com.gasolinator.a.app.helper;


public class DistanceHelper
{
    private static double Radius = 6371.0D;

    public static double haversineFormula(double latVal1,double lonVal1, double latVal2, double lonVal2){
        double dist = 0.0;
        double deltaLat = Math.toRadians(latVal2 - latVal1);
        double deltaLon = Math.toRadians(lonVal2 - lonVal1);
        latVal1 = Math.toRadians(latVal1);
        latVal2 = Math.toRadians(latVal2);
        lonVal1 = Math.toRadians(lonVal1);
        lonVal2 = Math.toRadians(lonVal2);
        double a = Math.sin(deltaLat/2) * Math.sin(deltaLat/2) + Math.cos(latVal1) * Math.cos(latVal2) * Math.sin(deltaLon/2) * Math.sin(deltaLon/2);
        double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
        dist = Radius * c;
        return dist*1000;
    }

    public static double cosineFormula(double lat1, double lon1, double lat2, double lon2) {
        double latA = Math.toRadians(lat1);
        double lonA = Math.toRadians(lon1);
        double latB = Math.toRadians(lat2);
        double lonB = Math.toRadians(lon2);
        double cosAng = (Math.cos(latA) * Math.cos(latB) * Math.cos(lonB-lonA)) + (Math.sin(latA) * Math.sin(latB));
        double ang = Math.acos(cosAng);
        double dist = ang * Radius;
        return dist*1000;
    }
}